<template>
    <div id="AsnDetailList">
        <v-tableTitle :btnConfig="btnConfig" :tableSelectData="selectData" @backList="backList"
                      @del="del" @newCreate="newCreate"></v-tableTitle>
        <div class="detail">
            <v-navMenu
                    :detailNav="detailNav"
                    :menuData="menuData"
                    @setMentActive="setMentActive"
                    v-if="detailNav=='1'||detailNav=='2'"
            ></v-navMenu>
            <component :data="{detailData,argument,detailSelectData,type}" :is="currentComponent"></component>
        </div>
    </div>

</template>

<script>
    import tableTitle from "commons/TableTitle";
    import navMenu from "commons/NavMenu";
    import baseMixin from "@/mixins/BaseMixin";
    import config from "../Config"

    export default {
        name: "DetailList",
        mixins: [baseMixin, config],
        data() {
            return {
                newFlag: false,
                argument: {},
                detailData: {},
                selectData: [],
                menuData: [
                    {label: this.$t("bill.filter"), index: "1"},
                    {label: this.$t("bill.transaction"), index: "2"},
                ],
                detailNav: "1",
                saveType: "filter",
                componentConfig: [
                    {
                        name: "activity_filter",
                        label: this.$t("bill.filter"),
                        component: () => import('./page/activity_filter.vue')
                    },
                    {
                        name: "activity_trans",
                        label: this.$t("bill.transaction"),
                        component: () => import('./page/activity_trans.vue')
                    },
                    {
                        name: "activity_tableDetail",
                        label: this.$t('common.detail'),
                        component: () => import('./page/activity_tableDetail.vue')
                    },
                ],
                detailSelectData: {},
                type: ""
            }
        },
        computed: {
            btnConfig() {
                if (this.$store.state.newFlag) {
                    return []
                } else if (this.detailNav == 1 || this.detailNav == 2) {
                    return [
                        {label: this.$t('common.create'), invalid: "newCreate"},
                        {label: this.$t('common.delete'), disabled: true, invalid: "del"},
                    ]
                } else {
                    return [
                        {label: this.$t('common.return'),  invalid: "backList"},
                    ]
                }
            },
            currentComponent() {
                return this.componentConfig[this.detailNav - 1].component;
            }
        },
        methods: {
            //删除数据
            async del(data) {
                let url = "";
                if (this.detailNav == "2") {
                    url = `/deleteActivityTrans/${this.$store.state.wms}`
                } else if (this.detailNav == "1") {
                    url = `/deleteActivityFilter/${this.$store.state.wms}`
                }
                try {
                    let res = await this.$api.post(url, data);
                        this.$message.success(res.returnMgr);
                        this.$children[2].getTableData(1, {})
                } catch (e) {
                    this.$message.error(e);
                } finally {
                    this.$children[2].$refs.table.delSelectData(data);
                }
            },
            //选中的数据
            setSelectData(data) {
                this.selectData = data;
            },
            //返回试图
            backList() {
                this.detailNav = "1";
            },
            //新建
            async newCreate(data) {
                if (this.detailNav == '1') {
                    this.type = "activity_filter";
                } else if (this.detailNav == '2') {
                    this.type = "activity_trans";
                }
                this.detailNav = '3'
            },
            //导航值
            setMentActive(key) {
                this.detailNav = key;
                this.selectData = [];
            },
            async setdialog(data, type) {
                let url = ""
                this.type = type;
                if (type == "activity_filter") {
                    url = `/queryActivityFilterByCode/${this.$store.state.wms}/${this.argument.filter_id}`
                } else if (type == "activity_trans") {
                    url = `/queryActivityTransByCode/${this.$store.state.wms}/${data.id}`
                }
                this.detailSelectData = data;
                try {
                    let res = await this.$api.get(url);
                        this.detailData = res.bean;
                        this.detailNav = "3";
                } catch (e) {
                    this.$message.error(e);
                }


            }
        },
        mounted() {
            
            this.newFlag = this.$store.state.newFlag;
            if (this.newFlag) {

            } else if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                this.argument = data.routeData;
                this.detailData = data.detailList;
                this.detailNav = data.detailListNav;
            } else {
                this.argument = this.$store.state.routeData;
            }

        },
        components: {
            "v-tableTitle": tableTitle,
            "v-navMenu": navMenu,
        },
        watch: {
            selectData(data) {
                if (this.permissionStatus) {
                    if (data.length > 0) {
                        this.deleteStatus = false;
                    } else {
                        this.deleteStatus = true;
                    }
                }
            },
            detailNav(data) {
                if (data == '2') {
                    this.saveType = "trans";
                } else if (data == '1') {
                    this.saveType = "filter";
                }
                this.selectData = [];
            }
        }
    }
</script>

<style>

</style>
